﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KP_CommonLibrary.KP_CommonControls;
using KP_CommonLibrary.KP_CoreUI;
using KP_CommonLibrary;
using KP_CommonLibrary.Logs;
using KEEPER_BRR_13dotNET.BusinessLogic;
namespace KEEPER_BRR_13dotNET.Presentation.List
{
    public partial class Frm_GiayToKemTheoEdit : KP_CommonLibrary.KP_CoreUI.KP_EditListItem
    {
        public Frm_GiayToKemTheoEdit()
        {
            InitializeComponent();
        }
        public override void CustomWriteData(DataRow row)
        {
            if (cboLoaiGiayTo.SelectedValue != null)
            {
                row["Ten_LoaiGt"] = cboLoaiGiayTo.Text;
            }
            base.CustomReadData(row);
        }
        public override void LoadDependencyData()
        {
            try
            {
                BL_KPDmLoaiGt blLoaiGt = new BL_KPDmLoaiGt();
                cboLoaiGiayTo.DataSource = blLoaiGt.Select();
                base.LoadDependencyData();
            }
            catch (Exception ex)
            {
                LogUtil.Logger.Fatal("Lấy danh sách giấy tờ \n", ex);
                KPMessageBox.Show("Lấy danh sách giấy tờ \n" + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
            }
        }
        public override void InitData(DataRow row)
        {
            row["Loai_DoiTuong"] = (LoaiDoiTuong == null ? DBNull.Value : (object)LoaiDoiTuong);
            row["Ma_DoiTuong"] = (DoiTuongId == null ? DBNull.Value : (object)DoiTuongId);
            row["Vi_Tri"] = row.Table.Rows.Count + 1;
            row["Bat_Buoc"] = false;
            base.InitData(row);
        }

        public string DoiTuongId { get; set; }
        public string LoaiDoiTuong { get; set; }

        public override void SaveAndClose()
        {
            string state = "";
            try
            {

                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Kết thúc cập nhật\n";
                    EndEdit();

                    state = "Lưu dữ liệu\n";
                    FormState = FormState.Unspecified;
                    Close();
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
        public override void SaveAndNew()
        {

            string state = "Lưu thông tin\n";
            try
            {
                state = "Kết thúc cập nhật\n";
                EndEdit();
                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Lưu thông tin\n";
                    FormState = FormState.Unspecified;
                    state = "Khởi tạo bản ghi mới\n";
                    AddNew(ParentBinding);
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
        private void panelEx1_Click(object sender, EventArgs e)
        {

        }
    }
}
